#include "mysystemtrayicon.h"
#include <QIcon>
#include <QAction>
#include <QDebug>

MySystemTrayIcon::MySystemTrayIcon(QObject *parent) :
    QObject(parent)
{
    trayIcon = new QSystemTrayIcon(this);
    trayIconMenu = new QMenu;
    QAction *actionMin = new QAction(QIcon(":/pic/mini"), tr("最小化"), this);
    connect(actionMin, SIGNAL(triggered()), this, SIGNAL(sig_actionMin()));

    QAction *actionNormal = new QAction(QIcon(":/pic/normal"), tr("显示窗口"), this);     //----图片
    connect(actionNormal, SIGNAL(triggered()), this, SIGNAL(sig_actionNormal()));

    QAction *actionQuit = new QAction(QIcon(":/pic/close"), tr("退出"), this);
    connect(actionQuit, SIGNAL(triggered()), this, SIGNAL(sig_actionQuit()));


    trayIconMenu->addAction(actionMin);
    trayIconMenu->addAction(actionNormal);
    trayIconMenu->addAction(actionQuit);
    trayIcon->setContextMenu(trayIconMenu);
}
MySystemTrayIcon::~MySystemTrayIcon()
{
    delete trayIconMenu;
}

void MySystemTrayIcon::setIcon(QString url)
{
    trayIcon->setIcon(QIcon(url));
}

void MySystemTrayIcon::setToolTip(QString toolTip)
{
    trayIcon->setToolTip(toolTip);
}

void MySystemTrayIcon::show()
{
    trayIcon->show();
}

void MySystemTrayIcon::hide()
{
    trayIcon->hide();
}

void MySystemTrayIcon::showMessage(QString tital, QString msg, int timeOut, QSystemTrayIcon::MessageIcon icon)
{
    trayIcon->showMessage(tital, msg, icon, timeOut);
}
